{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Pandas数据排序"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Series的排序：<br>\n",
    "***Series.sort_value(ascending=Ture,inplace=Flase)***\n",
    "参数说明：\n",
    "   * ascending: 默认为True升序排序，为False降序排序\n",
    "   * inplace: 是否修改原始Series\n",
    "    \n",
    "DataFrame的排序:<br>\n",
    "***DataFrame.sort_values(by,ascending=True,inplace=False)***\n",
    "参数说明：\n",
    "   * by: 字符串或者List<字符串>，单列排序或者多列排序\n",
    "   * ascending: bool或者list,升序还是降序，如果是list对应by的多列\n",
    "   * inplace: 是否修改原始DataFrame"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 0. 读取数据"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "fpath=\"../datas/weather_20230115134249.csv\"\n",
    "df = pd.read_csv(fpath)\n",
    "\n",
    "# 替换温度的后缀℃\n",
    "df.loc[:,\"气温(度)\"] = df[\"气温(度)\"].str.replace(\"℃\",\"\").astype(\"float\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>日期</th>\n",
       "      <th>城市</th>\n",
       "      <th>行政区</th>\n",
       "      <th>观测站</th>\n",
       "      <th>气温(度)</th>\n",
       "      <th>相对湿度(%)</th>\n",
       "      <th>累积雨量(mm)</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>2015-01-01</td>\n",
       "      <td>新北市</td>\n",
       "      <td>烏來區</td>\n",
       "      <td>福山</td>\n",
       "      <td>13.7</td>\n",
       "      <td>92</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>2015-01-02</td>\n",
       "      <td>臺南市</td>\n",
       "      <td>安平區</td>\n",
       "      <td>安平</td>\n",
       "      <td>23.5</td>\n",
       "      <td>70</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>2015-01-03</td>\n",
       "      <td>臺東縣</td>\n",
       "      <td>東河鄉</td>\n",
       "      <td>七塊厝</td>\n",
       "      <td>19.6</td>\n",
       "      <td>86</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>2015-01-04</td>\n",
       "      <td>新北市</td>\n",
       "      <td>貢寮區</td>\n",
       "      <td>福隆</td>\n",
       "      <td>14.2</td>\n",
       "      <td>96</td>\n",
       "      <td>-99.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>2015-01-05</td>\n",
       "      <td>南投縣</td>\n",
       "      <td>仁愛鄉</td>\n",
       "      <td>小奇萊</td>\n",
       "      <td>8.3</td>\n",
       "      <td>57</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "           日期   城市  行政区  观测站  气温(度)  相对湿度(%)  累积雨量(mm)\n",
       "0  2015-01-01  新北市  烏來區   福山   13.7       92       0.0\n",
       "1  2015-01-02  臺南市  安平區   安平   23.5       70       0.0\n",
       "2  2015-01-03  臺東縣  東河鄉  七塊厝   19.6       86       0.0\n",
       "3  2015-01-04  新北市  貢寮區   福隆   14.2       96     -99.0\n",
       "4  2015-01-05  南投縣  仁愛鄉  小奇萊    8.3       57       0.0"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.head()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 1. Series的排序"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "381   -9900\n",
       "162   -9900\n",
       "453   -9900\n",
       "470   -9900\n",
       "24    -9900\n",
       "Name: 相对湿度(%), dtype: int64"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 升序排序\n",
    "df[\"相对湿度(%)\"].sort_values().head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "352    100\n",
       "49     100\n",
       "95     100\n",
       "274    100\n",
       "167    100\n",
       "Name: 相对湿度(%), dtype: int64"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 降序排序\n",
    "df[\"相对湿度(%)\"].sort_values(ascending=False).head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "286     七堵區\n",
       "329     七股區\n",
       "411    三地門鄉\n",
       "20      三峽區\n",
       "276     三星鄉\n",
       "Name: 行政区, dtype: object"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df[\"行政区\"].sort_values().head()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 2. DataFrame的排序"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 2.1 单列排序"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>日期</th>\n",
       "      <th>城市</th>\n",
       "      <th>行政区</th>\n",
       "      <th>观测站</th>\n",
       "      <th>气温(度)</th>\n",
       "      <th>相对湿度(%)</th>\n",
       "      <th>累积雨量(mm)</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>381</th>\n",
       "      <td>2016-01-17</td>\n",
       "      <td>高雄市</td>\n",
       "      <td>梓官區</td>\n",
       "      <td>梓官</td>\n",
       "      <td>-99.0</td>\n",
       "      <td>-9900</td>\n",
       "      <td>-99.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>162</th>\n",
       "      <td>2015-06-12</td>\n",
       "      <td>臺中市</td>\n",
       "      <td>烏日區</td>\n",
       "      <td>烏日</td>\n",
       "      <td>-99.0</td>\n",
       "      <td>-9900</td>\n",
       "      <td>-99.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>453</th>\n",
       "      <td>2016-03-29</td>\n",
       "      <td>屏東縣</td>\n",
       "      <td>長治鄉</td>\n",
       "      <td>長治</td>\n",
       "      <td>-99.0</td>\n",
       "      <td>-9900</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>470</th>\n",
       "      <td>2016-04-15</td>\n",
       "      <td>新北市</td>\n",
       "      <td>永和區</td>\n",
       "      <td>永和</td>\n",
       "      <td>-99.0</td>\n",
       "      <td>-9900</td>\n",
       "      <td>-99.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>24</th>\n",
       "      <td>2015-01-25</td>\n",
       "      <td>臺中市</td>\n",
       "      <td>西屯區</td>\n",
       "      <td>西屯</td>\n",
       "      <td>-99.0</td>\n",
       "      <td>-9900</td>\n",
       "      <td>-99.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "             日期   城市  行政区 观测站  气温(度)  相对湿度(%)  累积雨量(mm)\n",
       "381  2016-01-17  高雄市  梓官區  梓官  -99.0    -9900     -99.0\n",
       "162  2015-06-12  臺中市  烏日區  烏日  -99.0    -9900     -99.0\n",
       "453  2016-03-29  屏東縣  長治鄉  長治  -99.0    -9900       0.0\n",
       "470  2016-04-15  新北市  永和區  永和  -99.0    -9900     -99.0\n",
       "24   2015-01-25  臺中市  西屯區  西屯  -99.0    -9900     -99.0"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 升序排序\n",
    "df.sort_values(by=\"相对湿度(%)\").head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>日期</th>\n",
       "      <th>城市</th>\n",
       "      <th>行政区</th>\n",
       "      <th>观测站</th>\n",
       "      <th>气温(度)</th>\n",
       "      <th>相对湿度(%)</th>\n",
       "      <th>累积雨量(mm)</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>49</th>\n",
       "      <td>2015-02-19</td>\n",
       "      <td>宜蘭縣</td>\n",
       "      <td>南澳鄉</td>\n",
       "      <td>西德山</td>\n",
       "      <td>9.1</td>\n",
       "      <td>100</td>\n",
       "      <td>4.5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>392</th>\n",
       "      <td>2016-01-28</td>\n",
       "      <td>宜蘭縣</td>\n",
       "      <td>大同鄉</td>\n",
       "      <td>南山</td>\n",
       "      <td>10.4</td>\n",
       "      <td>100</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>21</th>\n",
       "      <td>2015-01-22</td>\n",
       "      <td>宜蘭縣</td>\n",
       "      <td>頭城鎮</td>\n",
       "      <td>桃源谷</td>\n",
       "      <td>11.3</td>\n",
       "      <td>100</td>\n",
       "      <td>20.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>384</th>\n",
       "      <td>2016-01-20</td>\n",
       "      <td>花蓮縣</td>\n",
       "      <td>鳳林鎮</td>\n",
       "      <td>鳳林山</td>\n",
       "      <td>14.3</td>\n",
       "      <td>100</td>\n",
       "      <td>2.5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>70</th>\n",
       "      <td>2015-03-12</td>\n",
       "      <td>臺北市</td>\n",
       "      <td>北投區</td>\n",
       "      <td>大屯山</td>\n",
       "      <td>7.3</td>\n",
       "      <td>100</td>\n",
       "      <td>6.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "             日期   城市  行政区  观测站  气温(度)  相对湿度(%)  累积雨量(mm)\n",
       "49   2015-02-19  宜蘭縣  南澳鄉  西德山    9.1      100       4.5\n",
       "392  2016-01-28  宜蘭縣  大同鄉   南山   10.4      100       0.0\n",
       "21   2015-01-22  宜蘭縣  頭城鎮  桃源谷   11.3      100      20.0\n",
       "384  2016-01-20  花蓮縣  鳳林鎮  鳳林山   14.3      100       2.5\n",
       "70   2015-03-12  臺北市  北投區  大屯山    7.3      100       6.0"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 降序排序\n",
    "df.sort_values(by=\"相对湿度(%)\",ascending=False).head()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 2.2 多列排序"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>日期</th>\n",
       "      <th>城市</th>\n",
       "      <th>行政区</th>\n",
       "      <th>观测站</th>\n",
       "      <th>气温(度)</th>\n",
       "      <th>相对湿度(%)</th>\n",
       "      <th>累积雨量(mm)</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>15</th>\n",
       "      <td>2015-01-16</td>\n",
       "      <td>苗栗縣</td>\n",
       "      <td>造橋鄉</td>\n",
       "      <td>造橋</td>\n",
       "      <td>-99.0</td>\n",
       "      <td>-9900</td>\n",
       "      <td>-99.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>24</th>\n",
       "      <td>2015-01-25</td>\n",
       "      <td>臺中市</td>\n",
       "      <td>西屯區</td>\n",
       "      <td>西屯</td>\n",
       "      <td>-99.0</td>\n",
       "      <td>-9900</td>\n",
       "      <td>-99.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>52</th>\n",
       "      <td>2015-02-22</td>\n",
       "      <td>南投縣</td>\n",
       "      <td>仁愛鄉</td>\n",
       "      <td>奇萊稜線A</td>\n",
       "      <td>-99.0</td>\n",
       "      <td>-9900</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>132</th>\n",
       "      <td>2015-05-13</td>\n",
       "      <td>臺南市</td>\n",
       "      <td>西港區</td>\n",
       "      <td>西港</td>\n",
       "      <td>-99.0</td>\n",
       "      <td>-9900</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>158</th>\n",
       "      <td>2015-06-08</td>\n",
       "      <td>屏東縣</td>\n",
       "      <td>新埤鄉</td>\n",
       "      <td>新埤</td>\n",
       "      <td>-99.0</td>\n",
       "      <td>-9900</td>\n",
       "      <td>-99.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "             日期   城市  行政区    观测站  气温(度)  相对湿度(%)  累积雨量(mm)\n",
       "15   2015-01-16  苗栗縣  造橋鄉     造橋  -99.0    -9900     -99.0\n",
       "24   2015-01-25  臺中市  西屯區     西屯  -99.0    -9900     -99.0\n",
       "52   2015-02-22  南投縣  仁愛鄉  奇萊稜線A  -99.0    -9900       0.0\n",
       "132  2015-05-13  臺南市  西港區     西港  -99.0    -9900       0.0\n",
       "158  2015-06-08  屏東縣  新埤鄉     新埤  -99.0    -9900     -99.0"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 按湿度、温度排序，默认升序\n",
    "df.sort_values(by=[\"相对湿度(%)\",\"气温(度)\"]).head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>日期</th>\n",
       "      <th>城市</th>\n",
       "      <th>行政区</th>\n",
       "      <th>观测站</th>\n",
       "      <th>气温(度)</th>\n",
       "      <th>相对湿度(%)</th>\n",
       "      <th>累积雨量(mm)</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>167</th>\n",
       "      <td>2015-06-17</td>\n",
       "      <td>彰化縣</td>\n",
       "      <td>芳苑鄉</td>\n",
       "      <td>芳苑</td>\n",
       "      <td>19.5</td>\n",
       "      <td>100</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>399</th>\n",
       "      <td>2016-02-04</td>\n",
       "      <td>臺東縣</td>\n",
       "      <td>大武鄉</td>\n",
       "      <td>山豬窟</td>\n",
       "      <td>19.0</td>\n",
       "      <td>100</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>291</th>\n",
       "      <td>2015-10-19</td>\n",
       "      <td>花蓮縣</td>\n",
       "      <td>玉里鎮</td>\n",
       "      <td>德武</td>\n",
       "      <td>17.8</td>\n",
       "      <td>100</td>\n",
       "      <td>1.5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>292</th>\n",
       "      <td>2015-10-20</td>\n",
       "      <td>花蓮縣</td>\n",
       "      <td>瑞穗鄉</td>\n",
       "      <td>舞鶴</td>\n",
       "      <td>16.8</td>\n",
       "      <td>100</td>\n",
       "      <td>1.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>111</th>\n",
       "      <td>2015-04-22</td>\n",
       "      <td>花蓮縣</td>\n",
       "      <td>光復鄉</td>\n",
       "      <td>富源</td>\n",
       "      <td>16.5</td>\n",
       "      <td>100</td>\n",
       "      <td>1.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "             日期   城市  行政区  观测站  气温(度)  相对湿度(%)  累积雨量(mm)\n",
       "167  2015-06-17  彰化縣  芳苑鄉   芳苑   19.5      100       0.0\n",
       "399  2016-02-04  臺東縣  大武鄉  山豬窟   19.0      100       0.0\n",
       "291  2015-10-19  花蓮縣  玉里鎮   德武   17.8      100       1.5\n",
       "292  2015-10-20  花蓮縣  瑞穗鄉   舞鶴   16.8      100       1.0\n",
       "111  2015-04-22  花蓮縣  光復鄉   富源   16.5      100       1.0"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 两个字段都是降序\n",
    "df.sort_values(by=[\"相对湿度(%)\",\"气温(度)\"],ascending=False).head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>日期</th>\n",
       "      <th>城市</th>\n",
       "      <th>行政区</th>\n",
       "      <th>观测站</th>\n",
       "      <th>气温(度)</th>\n",
       "      <th>相对湿度(%)</th>\n",
       "      <th>累积雨量(mm)</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>104</th>\n",
       "      <td>2015-04-15</td>\n",
       "      <td>臺中市</td>\n",
       "      <td>北屯區</td>\n",
       "      <td>大坑</td>\n",
       "      <td>22.8</td>\n",
       "      <td>-9900</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>286</th>\n",
       "      <td>2015-10-14</td>\n",
       "      <td>基隆市</td>\n",
       "      <td>七堵區</td>\n",
       "      <td>七堵</td>\n",
       "      <td>12.6</td>\n",
       "      <td>-9900</td>\n",
       "      <td>27.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>15</th>\n",
       "      <td>2015-01-16</td>\n",
       "      <td>苗栗縣</td>\n",
       "      <td>造橋鄉</td>\n",
       "      <td>造橋</td>\n",
       "      <td>-99.0</td>\n",
       "      <td>-9900</td>\n",
       "      <td>-99.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>24</th>\n",
       "      <td>2015-01-25</td>\n",
       "      <td>臺中市</td>\n",
       "      <td>西屯區</td>\n",
       "      <td>西屯</td>\n",
       "      <td>-99.0</td>\n",
       "      <td>-9900</td>\n",
       "      <td>-99.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>52</th>\n",
       "      <td>2015-02-22</td>\n",
       "      <td>南投縣</td>\n",
       "      <td>仁愛鄉</td>\n",
       "      <td>奇萊稜線A</td>\n",
       "      <td>-99.0</td>\n",
       "      <td>-9900</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "             日期   城市  行政区    观测站  气温(度)  相对湿度(%)  累积雨量(mm)\n",
       "104  2015-04-15  臺中市  北屯區     大坑   22.8    -9900       0.0\n",
       "286  2015-10-14  基隆市  七堵區     七堵   12.6    -9900      27.0\n",
       "15   2015-01-16  苗栗縣  造橋鄉     造橋  -99.0    -9900     -99.0\n",
       "24   2015-01-25  臺中市  西屯區     西屯  -99.0    -9900     -99.0\n",
       "52   2015-02-22  南投縣  仁愛鄉  奇萊稜線A  -99.0    -9900       0.0"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#分别指定升序和降序\n",
    "df.sort_values(by=[\"相对湿度(%)\",\"气温(度)\"],ascending=[True,False]).head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
